import {
    Controller,
    Get,
    Post,
    Put,
    Del,
    Param,
    Body,
    Inject,
  } from '@midwayjs/core';
  import { SubsystemService } from '../service/Subsystem.service';
  import { CreateSubsystemDto, UpdateSubsystemDto } from '../dto/Subsystem.dto';
  
  @Controller('/subsystem')
  export class SubsystemController {
    @Inject()
    private subsystemService: SubsystemService;
  
    // 获取所有子系统
    @Get('/')
    async getAllSubsystems() {
      const result = await this.subsystemService.getAllSubsystems();
      return {
        success: true,
        data: result.data,
        message: result.message,
      };
    }
  
    // 根据 ID 获取子系统
    @Get('/:id')
    async getSubsystemById(@Param('id') id: string) {
      const result = await this.subsystemService.getSubsystemById(id);
      if (!result.success) {
        return { success: false, message: result.message, status: 404 };
      }
      return { success: true, data: result.data, message: result.message };
    }
  
    // 创建新子系统
    @Post('/')
    async createSubsystem(@Body() body: CreateSubsystemDto) {
      const result = await this.subsystemService.createSubsystem(body);
      if (!result.success) {
        return { success: false, message: result.message, status: 400 };
      }
      return { success: true, data: result.data, message: result.message };
    }
  
    // 更新子系统
    @Put('/:id')
    async updateSubsystem(@Param('id') id: string, @Body() body: UpdateSubsystemDto) {
      const result = await this.subsystemService.updateSubsystem(id, body);
      if (!result.success) {
        return { success: false, message: result.message, status: 404 };
      }
      return { success: true, data: result.data, message: result.message };
    }
  
    // 删除子系统
    @Del('/:id')
    async deleteSubsystem(@Param('id') id: string) {
      const result = await this.subsystemService.deleteSubsystem(id);
      if (!result.success) {
        return { success: false, message: result.message, status: 404 };
      }
      return { success: true, message: result.message };
    }
  }
  